<?php
class BaseModelParams {
    /**
     * single object instance
     * @var protected static, default is null
     */
	protected static $instance = NULL;
	/**
	 * $_GET method parameters
	 * @var protected static, default is null
	 */
	protected static $get      = NULL;
	/**
	 * $_POST method parameters
	 * @var protected static, default is null
	 */
	protected static $post     = NULL;
	/**
	 * combined the $_GET and $_POST parameters
	 * @var protected static, default is null
	 */
	protected static $com      = NULL;
    
	/**
	 * constructor, private
	 */
    private function __construct(){
        return;
    }
	/**
	 * init the parameters method
	 */
	public function __init() {
		 self::$get  = &$_GET; 
		 self::$post = &$_POST;
		 foreach( self::$get as $key => $value ) {
			self::$com[$key] = &self::$get[$key];
		 }
		 foreach( self::$post as $key => $value ) {
			self::$com[$key] = &self::$post[$key];
		 }
	}
	/**
	 * single instance
	 */
	public static function &instance() {
		if( !self::$instance ) {
			self::$instance = &new BaseModelParams();
			self::$instance->__init();
		}
		return self::$instance;
	}
	/**
	 * get the parameter from $_com
	 * @param string $key
	 * @return NULL or mixed
	 */
	public static function get($key=NULL) {
		self::$instance = &BaseModelParams::instance();
		return $key ? self::$com[$key] : self::$com;
	}
	/**
	 * set the parameter into $_com
	 * @param string $key
	 * @param mixed $value
	 * @return bool, only true will be returned
	 */
	public static function set($key,$value) {
		self::$instance = &BaseModelParams::instance();
		return self::$com[$key] = $value; 
	}
	/**
	 * get parameter from $_GET
	 * @param string $key
	 * @return mixed
	 */
	public static function getGet($key=NULL) {
		self::$instance = &BaseModelParams::instance();
		return $key ? self::$get[$key] : self::$get;
	}
	/**
	 * set paramter into $_GET
	 * @param string $key
	 * @param mixed $value
	 * @return bool, only be true
	 */
	public static function setGet($key,$value) {
		self::$instance = &BaseModelParams::instance();
		self::set($key,$value);
		return self::$get[$key] = $value; 
	}
	/**
	 * get parameter from $_POST
	 * @param string $key
	 * @return mixed
	 */
	public static function getPost($key=NULL) {
		self::$instance = &BaseModelParams::instance();
		return $key ? self::$post[$key] : self::$post;
	}
	/**
	 * set parameter into $_POST
	 * @param string $key
	 * @param mixed $value
	 * @return bool
	 */
	public static function setPost($key,$value) {
		self::$instance = &BaseModelParams::instance();
		self::set($key,$value);
		return self::$post[$key] = $value; 
	}	
	/**
	 * get parameter from $_SERVER
	 * @param string $key
	 * @return mixed
	 */
    public static function getServer($key=NULL) {
		return empty($key) ? NULL : $_SERVER[$key];
	}
	/**
	 * set parameter into $_SERVER
	 * @return bool
	 */
	public static function setServer($key, $value) {
	    return $_SERVER[$key] = $value;
	}
}
?>